package com.shengqin.utils;

import com.shengqin.entity.SummaryResult;
import com.shengqin.entity.TestResult;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class BmiUtil {
    public static void buildLevel(SummaryResult summaryResult, Map<String, Long> bmiLevelMap) {
        List<TestResult> testResultList = summaryResult.getTestResultList();
        List<TestResult> bmiResults = testResultList.stream().filter(testResult -> testResult.getPrjName().equalsIgnoreCase("BMI")).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(bmiResults)) {
            bmiResults.forEach(testResult -> {
                if (StringUtils.hasLength(testResult.getLevel())) {
                    if (bmiLevelMap.containsKey(testResult.getLevel())) {
                        long result = bmiLevelMap.get(testResult.getLevel());
                        bmiLevelMap.put(testResult.getLevel(), result + 1);
                    } else {
                        bmiLevelMap.put(testResult.getLevel(), 1L);
                    }
                }
            });
        }
    }
}
